<template>
  <el-dialog title="设置角色" :visible="isShow" @close="closeFn">
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="item in checkBox" :key="item.id" :label="item.id">{{ item.title }}</el-checkbox>

    </el-checkbox-group>
    <template #footer>
      <el-row type="flex" justify="center">
        <el-button size="small" type="primary" @click="submit">确定</el-button>
        <el-button size="small" @click="closeFn">取消</el-button>
      </el-row>
    </template>
  </el-dialog>
</template>
<script>
import { getRoleList, updateEmploy, getEmployeeById } from '@/api/employee'
export default {
  props: {
    isShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      checkBox: [],
      checkList: [],
      curUserId: ''

    }
  },
  created() {
    this.getRolesList()
  },
  methods: {
    closeFn() {
      this.checkList = []
      this.$emit('update:isShow', false)

    //   this.$refs.form.resetFields()
    },
    async setPeopleRole(id) {
      this.curUserId = id
      const res = await getEmployeeById(id)
      console.log(49, res.data.roles)
      res.data.roles.forEach(item => {
        return this.checkList.push(item.id)
      })
    },
    async submit() {
      await updateEmploy({
        id: this.curUserId,
        roles: this.checkList

      })
      this.closeFn()
    },
    // 获取角色列表
    async getRolesList() {
      const res = await getRoleList({
        _limit: 1000,
        _start: this.start
      })
      console.log(res)
      this.checkBox = res.data
    }
  }
}
</script>

<style>

</style>
